import {defineConfig} from 'vite'
import path from 'node:path'
import electron from 'vite-plugin-electron/simple'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
    base:"./",
    publicPath:"./public",
    plugins: [
        react(),
        electron({
            main: {
                // Shortcut of `build.lib.entry`.
                entry: 'electron/main.ts',
            },
            preload: {
                // Shortcut of `build.rollupOptions.input`.
                // Preload scripts may contain Web assets, so use the `build.rollupOptions.input` instead `build.lib.entry`.
                input: path.join(__dirname, 'electron/preload.ts'),
            },
            // Ployfill the Electron and Node.js built-in modules for Renderer process.
            // See 👉 https://github.com/electron-vite/vite-plugin-electron-renderer
            renderer: {},
        }),
    ],
    server: {
        //前端的host和port
        // host: "192.168.1.86",
        // host: "127.0.0.1",
        port: 9987, // 指定端口号 3000
        //跨域代理设置===> api开头的请求都会被代理   demo: /api/xxx = http://127.0.0.1:8123/xxx
        // proxy: {
        //   '/api': {   //表示对以 /api 开头的请求进行代理
        //     target: 'http://127.0.0.1:8123/', //服务端ip
        //     changeOrigin: true,// 允许跨域
        //     rewrite: path => path.replace(/^\/api/, '')// 将请求url里的api去掉
        //   },
        // },
    },
})
